/*  Copyright (C) 2012 Philip Smith
 *
 *  This file is part of SuperChat.
 *
 *  SuperChat is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  SuperChat is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with SuperChat.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.supertycoon.bukkit.superchat;

import java.util.HashSet;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class PlayerShit {
	boolean splitMode = false;
	boolean historyMode = false;
	boolean isIgnoringMain = false;
	CommandSender player;
	ChatRoom last;
	ChatRoom toggle;
	HashSet<ChatRoom> primary;
	HashSet<ChatRoom> secondary;

	public PlayerShit(CommandSender player) {
		this.player = player;
		this.last = null;
		this.toggle = null;
		this.primary = new HashSet<ChatRoom>(5);
		this.secondary = new HashSet<ChatRoom>(0);
	}

	void dispatch(ChatRoom room, String message) {
		if (this.splitMode) {

		}
		if (this.historyMode) {

		}
		if (room.modroom)
			this.player.sendMessage(ChatColor.DARK_RED.toString() + '[' + ChatColor.RED.toString() + room.name
					+ ChatColor.DARK_RED.toString() + ']' + message);
		else
			this.player.sendMessage(ChatColor.DARK_BLUE.toString() + '[' + ChatColor.BLUE.toString() + room.name
					+ ChatColor.DARK_BLUE.toString() + ']' + message);
	}

	void toggledChat(String message) {
		((Player) this.player).chat("/chat " + this.toggle.name + ' ' + message);
	}

	void refresh() {

	}

	void addChatRoom(ChatRoom room) {
		this.primary.add(room);
		this.player.sendMessage(ChatColor.GRAY.toString() + "Joined room \"" + room.name + '"');
	}

	void quitChatRoom(ChatRoom room) {
		removeChatRoom(room);
		this.player.sendMessage(ChatColor.GRAY.toString() + "You have quit chat room \"" + room.name + '"');
	}

	void removeChatRoom(ChatRoom room) {
		this.primary.remove(room);
		this.secondary.remove(room);
	}

	boolean isMember(ChatRoom room) {
		if (this.primary.contains(room))
			return true;
		if (this.secondary.contains(room))
			return true;
		return false;
	}

	void quit() {
		SuperChat.mainIgnorers.remove(this.player);
		SuperChat.monitors.remove(this.player);
		SuperChat.toggled.remove(this.player);
		for (ChatRoom room : this.primary)
			room.removePlayer(this.player);
		for (ChatRoom room : this.secondary)
			room.removePlayer(this.player);
	}

	void stopIgnoringMain() {
		SuperChat.mainIgnorers.remove(this.player);
		this.isIgnoringMain = false;
		this.player.sendMessage(ChatColor.GRAY.toString() + "You have rejoined the main chat");
	}

	void ignoreMain() {
		SuperChat.mainIgnorers.add(this.player);
		this.isIgnoringMain = true;
		this.player.sendMessage(ChatColor.GRAY.toString() + "You have quit the main chat");
	}

	void toggle(ChatRoom room) {
		SuperChat.toggled.add(this.player);
		this.toggle = room;
		this.player.sendMessage(ChatColor.GRAY.toString() + "You have toggled chat room \"" + room.name + '"');
	}

	void disableToggle() {
		SuperChat.toggled.remove(this.player);
		this.toggle = null;
		this.player.sendMessage(ChatColor.GRAY.toString() + "You have disabled your chat room toggle");
	}

}
